<?php
session_start();
$image=imagecreatetruecolor(200,40);//底图
$bgcolor=imagecolorallocate($image,250,250,250);//背景色
imagefill($image,0,0,$bgcolor);//填充
$banner="";                 //标记出显示的数字
$face="simsun.ttc";//字体库名;可以在控制面板里搜索
$strdb=array("文","豆","一","起","打","酱","油","来");
//$strdb=ereg('['.chr(0xa1).'-'.chr(0xff).']', $str);
for($i=0;$i<4;$i++){   //取4个任意中文
    $cn=$strdb[rand(0,7)];
    $banner.=$cn;

    imagettftext($image,mt_rand(14,16),mt_rand(-60,60),(40*$i+20),mt_rand(30,35),$fontcolor,$face,$cn);
}
$_SESSION["che_codeimg"]=$banner;
for($i=0;$i<200;$i++) {//干扰点，200个
    $pointcolor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200));
    imagesetpixel($image, rand(1, 199), rand(1, 59), $pointcolor);
}
for($i=0;$i<3;$i++){//干扰线，三条
    $linecolor=imagecolorallocate($image, rand(80, 220), rand(80, 220), rand(80, 220));
    imageline($image,rand(1,199),rand(1,59),rand(1,199),rand(1,59),$linecolor);
}

header("Content-type:image/png");
imagepng($image);
?>